package com.leorui.schoollife.entity

import net.sf.json.JSONArray
import net.sf.json.JSONObject
import java.io.Serializable

// 获取朋友圈返回的结果
class FriendCircleMessageResponse : Serializable {
    private var status: Int? = null
    private var msg: String? = null
    private var currentPage: Int? = null
    private var haveMore: Boolean? = null
    private var messageList: List<FriendCircleMessage>? = null

    constructor(status: Int, msg: String?) : this(status, msg, null, null, null)

    constructor(status: Int, msg: String?, currentPage: Int?, haveMore: Boolean?, messageList: List<FriendCircleMessage>?) {
        this.status = status
        this.msg = msg
        this.currentPage = currentPage
        this.haveMore = haveMore
        this.messageList = messageList
    }

    fun toMap(): Map<Any?, Any?> {
        val json = JSONObject()
        json["status"] = status
        json["msg"] = msg
        json["currentPage"] = currentPage
        json["have_more"] = haveMore
        val messageJsonList = JSONArray()
        messageList?.forEach {
            messageJsonList.add(it.toMap())
        }
        json["friend_circle_message_list"] = messageJsonList.toList()
        return json.toMap()
    }
}

// 朋友圈消息
class FriendCircleMessage : Serializable {
    var conversationId: String? = null
    var account: String? = null
    var icon: PhotoEntity? = null
    var accountNickname: String? = null
    var location: String? = null
    var message: String? = null
    var time: String? = null
    var isLove: Boolean? = null
    var loveCount: Int? = null
    var commitList: List<FriendCircleCommitItem?>? = null
    fun toMap(): Map<Any?, Any?> {
        val json = JSONObject()
        json["conversation_id"] = conversationId
        json["message"] = message
        json["location"] = location
        json["sender_account"] = account
        json["sender_name"] = accountNickname
        json["sender_icon"] = icon?.toMap()
        json["agree_count"] = loveCount
        json["is_love"] = isLove
        json["time"] = time
        val commitListJson = JSONArray()
        commitList?.forEach {
            commitListJson.add(it?.toMap())
        }
        json["commit"] = commitListJson.toList()
        return json.toMap()
    }
}


class FriendCircleCommitResponse : Serializable {
    private var status: Int? = null
    private var msg: String? = null
    var commitItem: List<FriendCircleCommitItem?>? = null

    constructor(status: Int, msg: String?) : this(status, msg, null)
    constructor(status: Int, msg: String?, commitItem: List<FriendCircleCommitItem?>?) {
        this.status = status
        this.msg = msg
        this.commitItem = commitItem
    }

    fun toMap(): Map<Any?, Any?>? {
        val json = JSONObject()
        json["status"] = status
        json["msg"] = msg
        val list = JSONArray()
        commitItem?.forEach {
            list.add(it?.toMap())
        }
        json["commit_item"] = list.toList()
        return json.toMap()
    }
}

// 评论内容
class FriendCircleCommitItem : Serializable {
    var conversationId: String? = null
    var commitId: String? = null
    var commitTime: String? = null
    var commitMsg: String? = null
    var commitUser: StudentAccount? = null
    var commitToWho: StudentAccount? = null
    fun toJson(): JSONObject {
        val json = JSONObject()
        json["conversation_id"] = conversationId
        json["commit_id"] = commitId
        json["commit_message"] = commitMsg
        json["commit_time"] = commitTime
        json["commit_user"] = commitUser?.toJson()
        json["commit_to_who"] = commitToWho?.toJson()
        return json
    }

    fun toMap(): Map<Any?, Any?> {
        val json = JSONObject()
        json["conversation_id"] = conversationId
        json["commit_id"] = commitId
        json["commit_message"] = commitMsg
        json["commit_time"] = commitTime
        json["commit_user"] = commitUser?.toMap()
        json["commit_to_who"] = commitToWho?.toMap()
        return json.toMap()
    }
}
